package com.tistory.risk.controller;

import java.sql.SQLException;
import java.util.List;

import javax.servlet.http.HttpServletRequest;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import com.tistory.admin.adminmgr.auth.model.LoginUserInfo;
import com.tistory.admin.common.BaseException;
import com.tistory.admin.common.SessionManager;
import com.tistory.common.service.CommonService;
import com.tistory.common.vo.CommonCodeRes;
import com.tistory.common.vo.CommonReq;
import com.tistory.commons.utils.DateUtil;
import com.tistory.commons.utils.SessionUtil;
import com.tistory.commons.utils.StringUtil;
import com.tistory.risk.service.RiskService;

@Controller
public class RiskController {
	
	private static final Logger log = LoggerFactory.getLogger(RiskController.class);
	
	@Autowired
	private RiskService riskService;
	
	@Autowired
	private CommonService commonService;

	@RequestMapping(value="risk/stayList.do")
	public ModelAndView minusSearch(HttpServletRequest request , CommonReq req) throws SQLException{

		ModelAndView modelAndView = new ModelAndView();
		nvlStartEndDate(req);
		modelAndView.addObject("model", req);
		
		
		
		List<CommonCodeRes> commonCodeList  = commonService.getCommonCodeList("DP02");		// 카드사 코드 가져오기 
		modelAndView.addObject("commonCodeList", commonCodeList);
		modelAndView.setViewName("risk/stayList");
		
		// 권한체크
		modelAndView = SessionManager.init(request,modelAndView);
		return modelAndView;
	}	
	
	
	private void nvlStartEndDate(CommonReq req){
		if(StringUtil.isEmpty(req.getSearchStRegDt()) || StringUtil.isEmpty(req.getSearchEdRegDt())) {
			req.setSearchStRegDt(StringUtil.nvlStr(req.getSearchStRegDt(),DateUtil.getAddDay(-1, "yyyy-MM-dd")));
			req.setSearchEdRegDt(StringUtil.nvlStr(req.getSearchEdRegDt(),DateUtil.getSysDate("yyyy-MM-dd")));
        }
	};
}
